package com.demo.dao;

import com.demo.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper1 {
    @Select("select * from user")
    List<User> getAllUsers();
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "username", column = "u"),
            @Result(property = "address", column = "a")
    })
    @Select("select id as id, username as u, address as a from user where id = #{id}")
    User getUserById(Long id);

    @Select("select * from user where username like CONCAT('%',#{name},'%')")
    List<User> getUsersByName(String name);

    @Insert({"insert into user(username, address) values(#{username},#{address})"})
    @SelectKey(statement = "", keyProperty = "", before = false, resultType = Integer.class)
    Integer addUser(User user);

    @Update("update user set username = #{username}, address = #{address} where id = #{id}")
    Integer updateUserById(User user);

    @Delete("delete from user where id = #{id}")
    Integer deleteUserById(Integer id);
}
